#pragma once

#include <vector>
//#include <list>
using namespace std;

class Aobj;

class AobjRun{
private:
	int mrun;
public:
	AobjRun() { mrun = 0; }

	void run() { mrun = 1;}
	void stop() { mrun = 0;}
	void onStopped() { mrun = 2; }

	bool isRun() { return mrun == 1 ? true : false; }
	bool isStopped(){ return mrun == 2 ? true : false; }
};

class AobjStore{
protected:
	vector<Aobj *> mobjs;
	bool isExist(Aobj * obj) { return (find(obj)>=0)? true: false;}
	int find( Aobj * obj);

	void del( int idx);
	void del( Aobj * obj) { del(find(obj));}
	void clear() { mobjs.clear(); }	
public :
	int add( Aobj * obj);
	Aobj * get(int idx);
	int getCount() { return mobjs.size(); }

};
class AobjCreater: public AobjStore
{
public:
	void delAll();
};
class AobjInit : public AobjStore
{
public:
	int initAll();
	void exitAll();
};

enum AobjEnterId{ a_creat, a_destory, a_init, a_exit};
class AobjEnterCount{
private:
	int mcount[10];
public:
	AobjEnterCount();
	~AobjEnterCount(){}

	int check( int id){ ++mcount[id]; return get(id); }
	int get( int id) { return mcount[id]; }
};
// ----------20150620, start/stop count; --------
class AobjCounter{
private:
	int mstartcnt;
public:
	AobjCounter()
	{
		mstartcnt = 0;
	}
	void reset() { mstartcnt = 0; }
	int incCount(){ return ++mstartcnt; }
	int decCount(){ return --mstartcnt; }
	int getCount() { return mstartcnt; }
};
// -------------Aobjstuff -----------------------
class AstuffMan
{
public:
	wstring mobjname;
	const TCHAR * getObjName() { return mobjname.c_str(); }
	void setObjName(const TCHAR * s) { mobjname = s;}

	AobjRun *mobjrun;
	AobjCreater *mobjcreater;
	AobjInit *mobjinit;
	AobjEnterCount *mobjentercount;

	AobjCounter mobjcounter;	// 20150620;
	int checkCounterOnStart();
	int checkCountOnStop();
public:
	AstuffMan( Aobj * obj )
	{
		mobjrun=new AobjRun();
		mobjcreater = new AobjCreater();
		mobjinit = new AobjInit();
		mobjentercount = new AobjEnterCount();
	}
	~AstuffMan()
	{
		if( mobjrun) { delete mobjrun; mobjrun = NULL; }
		if( mobjcreater) { delete mobjcreater; mobjcreater = NULL; }
		if( mobjinit) { delete mobjinit; mobjinit= NULL; }
		if( mobjentercount) { delete mobjentercount; mobjentercount = NULL; }
	}
};
